package com.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 32. 解压报文
 * https://blog.csdn.net/weixin_42450130/article/details/131474924
 */
public class NiukeMoni32 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();

        int depth = 0; // 一个 "[" 增加一个深度，一个 "]" 减小一个深度
        StringBuilder sb = new StringBuilder();
        List<String[]> temp = new ArrayList<>();
        String[] item = null;
        int numStart = -1;
        int zimuStart = -1;
        for (int i = 0; i < input.length(); i++) {
            char curr = input.charAt(i);

            if (curr >= '0' && curr <= '9' && numStart == -1) {
                if (item != null) {
                    item[1] = input.substring(zimuStart, i);
                    System.out.println(Arrays.toString(item));
                    temp.add(item);
                    item = null;
                }
                numStart = i;
                zimuStart = -1;
            } else if (curr == '[') {
                item = new String[2];
                item[0] = input.substring(numStart, i);
                numStart = -1;
                depth++;
                zimuStart = i + 1;
            } else if (curr == ']') {
                if (item != null) {
                    item[1] = input.substring(zimuStart, i);
                    System.out.println(Arrays.toString(item));
                    temp.add(item);
                    item = null;
                }

                depth--;
                zimuStart = -1;
            }

            if (depth == 0) {
                if (temp.size() > 0) {
                    String str = "";
                    for (int j = temp.size() - 1; j >= 0; j--) {
                        String[] arr = temp.get(j);
                        String appendStr = arr[1] + str;
                        str = "";
                        for (int k = 0; k < Integer.parseInt(arr[0]); k++) {
                            str += appendStr;
                        }
                    }
                    sb.append(str);
                    temp.clear();
                } else if (curr != '[' && curr != ']'  && numStart == -1 && zimuStart == -1 && !(curr >= '0' && curr <= '9')) {
                    // 拼接不需要翻倍的正常字母
                    sb.append(curr);
                }
            }
        }

        System.out.println(sb);

    }

}
